import { ref } from 'vue'
import { getSongCatlist, getSonglist } from '@/service/find-music/songs-list'

export function InitGetData(cat: string, limit: any, offset: number) {
  //获取所有标签数据
  const tagslist: any = ref([])
  getSongCatlist().then((res: any) => {
    tagslist.value = res.tags.splice(0, 10)
  })

  //歌单数据
  const songsList = ref([])
  const totals = ref(0)
  //获取对应歌单数据
  getSongList(limit.value, offset, cat)
  function getSongList(limit: number, offset: number, cat: string) {
    getSonglist(limit, offset, cat).then((res: any) => {
      songsList.value = res.playlists
      totals.value = res.total
    })
  }

  const currentPage = ref(1)
  // 初始化的目的是为了每次点击标签都是从第一页数据开始
  function initRequest() {
    cat = '全部'
    limit.value = 30
    offset = 0
    currentPage.value = 1
  }

  return [tagslist, songsList, totals, getSongList, currentPage, initRequest]
}
